package medium最短无序连续子数组;

import org.testng.annotations.Test;

import java.util.Arrays;

public class Solution {

    public int findUnsortedSubarray(int[] nums) {
        int[] contrast =(int[]) nums.clone();
        Arrays.sort(nums);
        int start = -1;
        int end = -1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != contrast[i]){
                if (start == -1)
                    start = i;
                else
                    end = i;
            }
        }
        return start != -1 && end !=-1 ? end-start+1 : 0;
    }
    @Test
    public void test(){
        int[] nums = {2,6,4,8,10,9,15};
        findUnsortedSubarray(nums);
    }
}
